package com.cucn.ingmall.order.web;

import com.alipay.api.AlipayApiException;
import com.cucn.ingmall.order.config.AlipayTemplate;
import com.cucn.ingmall.order.service.OrderService;
import com.cucn.ingmall.order.service.PaymentInfoService;
import com.cucn.ingmall.order.vo.PayVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 支付
 *
 * @author KouChaoJie
 * @since: 2022/1/28 14:19
 */
@Controller
@Slf4j
public class PayWebController {
    @Resource
    private AlipayTemplate alipayTemplate;
    @Resource
    private OrderService orderService;

    @ResponseBody
    @GetMapping(value = "/aliPayOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);

        String pay = alipayTemplate.pay(payVo);
        log.info(pay);

        return pay;
    }
}
